{% extends 'layout.html' %}
{% from 'macro/page.html' import render_pagination %}

{% block main %}
<script>
function check_all(form)
{
    for(let i=0; i<form.elements.length; i++)
    {
         let e = form.elements[i]
         if(e.checked){
            e.checked = ''
         }else{
            e.checked = 'checked'
         }
    }
}

</script>
<div class="card">
    <div class="card-header">
        <div class="card-title">
            <a class="btn btn-info btn-sm" href="{{ url_for('admins.tag_create') }}">新增</a>
        </div>
        <div class="card-tools">
            <form>
                <div class="input-group input-group-sm" style="width: 150px;">
                    <input type="text" name="title" class="form-control float-right"
                           value="{{ request.args['title'] }}"
                           placeholder="Search">
                    <div class="input-group-append">
                        <button type="submit" class="btn btn-default"><i class="fas fa-search"></i></button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <!-- /.card-header -->
    <form name="list_form" method="post" action="">
        <div class="card-body table-responsive p-0" style="height:580px;">
            <table class="table table-hover table-head-fixed">
                <thead>
                <tr>
                    <th width="50px">#</th>
                    <th>ID</th>
                    <th>Tag名称</th>
                    <th>信息数</th>
                    <th>推荐</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for item in record.items %}
                <tr>
                    <td class="icheck-primary">
                        <input name="tag_ids" type="checkbox" id="tag_id_{{ item.id }}" value="{{ item.id }}">
                        <label for="tag_id_{{ item.id }}"></label>
                    </td>
                    <td>{{ item.id }}</td>
                    <td><a class="no-pjax" href="{{ item.url }}" target="_blank">{{ item.tag_name }}</a></td>
                    <td>{{ item.article|length }}</td>
                    <td>{{ '√' if item.good else '' }}</td>
                    <td>
                        <a class="btn btn-info btn-sm"
                           href="{{ url_for('admins.tag_modify', tag_id=item.id, next=request.full_path) }}">修改
                        </a>
                    </td>
                </tr>
                {% endfor %}
                </tbody>
            </table>

        </div>
        <!-- /.card-body -->
        <div class="card-footer clearfix row">
            <div class="col">
                <input type="button" class="btn btn-default btn-sm" value="全选/反选" onclick="return check_all(this.form)">
                <input type="submit" class="btn btn-primary btn-sm" value="推荐" name="confirm_good">
                <input type="submit" class="btn btn-secondary btn-sm" value="取消推荐" name="cancel_good">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
            </div>
            <div class="col">
                {{ render_pagination(record,align='right') }}
            </div>
        </div>
    </form>
</div>
<!-- /.card -->
{% endblock %}